/*
 * gpstime.h
 *
 *  Created on: 2020/12/04
 *      Author: hailiang
 */

#ifndef GPS_TIME_H
#define GPS_TIME_H

#include <cmath>

// GPS is now ahead of UTC by 18 seconds
#define GPS_LEAP_SECOND 18

class GpsTime {

public:
    static void gps2unix(int week, double sow, double &unixs) {
        unixs = sow + week * 604800 + 315964800 - GPS_LEAP_SECOND;
    };

    static void unix2gps(double unixs, int &week, double &sow) {
        double seconds = unixs + GPS_LEAP_SECOND - 315964800;

        week = floor(seconds / 604800);
        sow  = seconds - week * 604800;
    };
};

#endif // GPS_TIME_H
